package com.gsit.expenditure.view;

import javafx.application.Preloader;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class ApplicationPreloader extends Preloader{
	 private ProgressBar bar;
	 private Stage stage;
	   
	   
	    public void start(Stage stage) throws Exception {
	        this.stage = stage;
	        stage.setScene(createPreloaderScene());        
	        stage.show();
	    }
	   
	    @Override
	    public void handleProgressNotification(ProgressNotification pn) {
	        bar.setProgress(pn.getProgress());
	    }
	 
	    @Override
	    public void handleStateChangeNotification(StateChangeNotification evt) {
	        if (evt.getType() == StateChangeNotification.Type.BEFORE_START) {
	            stage.hide();
	        }
	    }    
	   
	    private Scene createPreloaderScene() {
	        bar = new ProgressBar();
	        final BorderPane pane = new BorderPane();
	        pane.setCenter(bar);
	        return new Scene(pane, 640, 480);        
	    }
	    
	    @Override
	    public void stop() throws Exception{
	    	super.stop();
	    	stage.hide();
	    }

}
